package za.org.jcicada.syshealth;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

import za.org.jcicada.genss.PhysicalURN;
import za.org.jcicada.genss.sensor.impl.Sensor;

public class PhysicalTreeCellRenderer extends DefaultTreeCellRenderer {

	private static final long serialVersionUID = 1L;
	
	private PhysicalModel physicalModel;
	
	public PhysicalTreeCellRenderer(PhysicalModel physicalModel) {
		this.physicalModel = physicalModel;
	}

	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value,
			boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
		super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
		DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
		PhysicalURN physicalURN = (PhysicalURN) treeNode.getUserObject();
		setText(physicalURN.getName());
		Sensor sensor = physicalModel.getSensor(physicalURN);
		setForeground(SensorColourMap.getSensorColor(sensor));
		return this;
	}

}
